package org.finesys.quartz.support;

import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.finesys.quartz.entity.SysJob;
import org.finesys.quartz.event.SysJobEvent;
import org.quartz.JobExecutionContext;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

/**
 * 转发定时任务事件
 */
@RequiredArgsConstructor
@Service
public class QuartzInvokeFactory {

    private final ApplicationEventPublisher applicationEventPublisher;

    /**
     * 发送定时任务
     */
    @SneakyThrows
    public void sendQuartzJob(SysJob sysJob, JobExecutionContext context) {
        applicationEventPublisher.publishEvent(new SysJobEvent(this, sysJob, context));
    }
}
